import sys, os
import shutil
import platform

SYSTEM = platform.system()

PRJ = 'lottery'
# 打包
if SYSTEM == 'Linux':
    strCmd = f'pyinstaller -n {PRJ} --add-data "bg.jpg:." --add-data "msyhmono.ttf:." -F lottery.py -w'
elif SYSTEM == 'Windows':
    strCmd = f'pyinstaller -n {PRJ} -F lottery.py -w'
os.system(strCmd)

# 清理环境
TARGETDIR = 'dist'
TEMPFILES = [TARGETDIR, 'build', '__pycache__', 'lottery.spec']
if SYSTEM == 'Linux':
    target = PRJ
elif SYSTEM == 'Windows':
    target = PRJ + '.exe'

if os.path.exists(target):
    os.remove(target)
shutil.move(os.path.join(TARGETDIR, target), '.')

for p in TEMPFILES:
    if os.path.isfile(p):
        os.remove(p)
    elif os.path.isdir(p):
        shutil.rmtree(p)
